﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSoftStore.BusinessLogic.Bill;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Client.UIL.ManageBilling;
using OpenSoftStore.Orm.Model;

namespace OpenSoftStore.Client.UIL.ManageMember.Info
{
    public partial class Bill : UserControl
    {
        private static Bill instance;
        public BillLogic LgcBill;
        public static Bill Instance
        {
            get { return instance ?? (instance = new Bill()); }
        }

        public Bill()
        {
            InitializeComponent();
            LgcBill = new BillLogic();
            SPACommon.SetUiStyle(this);
        }

        public void GetBills(T_Member member)
        {
            dgvBill.DataSource = LgcBill.GetBillView(" where T_Member.Id ='" + member.Id + "'");
            lblDgvGridTotal.Text = dgvBill.RowCount.ToString();
        }

        private void dgvBill_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvBill.CurrentRow == null) return;
            var id = dgvBill.CurrentRow.Cells["Id"].Value.ToString();

            var data = LgcBill.GetBillItemView(" where BillId = '" + id + "'");
            dgvBillItem.DataSource = data;
            lbldgvBillItemTotle.Text = dgvBillItem.RowCount.ToString();
        }

        private void tsbUpdate_Click(object sender, EventArgs e)
        {
            var billAdd = new BillAddWindow();
            if (dgvBill.CurrentRow == null) return;
            var id = dgvBill.CurrentRow.Cells["Id"].Value.ToString();
            billAdd.GetBill(id);
            billAdd.Show();
        }
    }
}
